const app = getApp();
Component({
  options: {
    styleIsolation: 'shared' 
  },
  properties: {
    type: {
      type: null,
      value: 'home'
    },
    tab_type: {
      type: null,
      value: '大厅'
    },
    mobile: {
      type: null,
      value: ''
    },
    skillService: {
      type: null,
      value: ''
    },
    // 抢单
    order_id: {
      type: null,
      value: ''
    }
  },
  /**
   * 页面的初始数据
   */
  data: {
    imgPath: app.globalData.imgPath,
  },

  lifetimes: {
    attached() {
    }
  },
  methods: {
    chooseType(item) {
      switch (item.currentTarget.dataset.value) {
        case '订单':
          wx.redirectTo({
            url:  `/packageJ/anytime_service/order/index/index`,
          });
          break;
        case '大厅':
          wx.redirectTo({
            url:  `/packageJ/anytime_service/home/index/index`,
          });
            break;
        case '我的':
          wx.redirectTo({
            url:  `/packageJ/anytime_service/my/index/index`,
          });
              break;
        case '发布需求':
              this.check_apply(1);
              break;
        case '技能需求':
            this.check_apply(2)
            break;
        default:
          break;
      } 
    },
    gophone() {
      wx.makePhoneCall({
        phoneNumber: this.data.mobile
      });
    },
    check_apply(role){
      app._getNetWork({
        url:app.getNetAddresss('plugin.be-within-call.frontend.role-apply.detail'),
        data:{role,validate_page:1},
        success:resdata=>{
          let {result,data} = resdata.data;
          if(result){
            if(role==1){
              if(data.apply_status!==1){
                wx.navigateTo({
                  url: '/packageJ/anytime_service/my/role_apply_for/promulgator/promulgator?role=1',
                })
              }else{
                wx.navigateTo({
                  url:  `/packageJ/anytime_service/my/Demand/Demand?type=1`,
                });
              }
            }else{
              if (data.apply_status !== 1) {
                wx.navigateTo({
                  url: '/packageJ/anytime_service/my/role_apply_for/master_worker/master_worker?apply_type=1',
                })
              }else{
                wx.navigateTo({
                  url:  `/packageJ/anytime_service/my/skill_manage/skill_manage`,
                });
              }
            }
          }
        }
      })
    },
    // 预约
    tabAppointment() {
      wx.navigateTo({
        url:  `/packageJ/anytime_service/home/order/index?id=${this.data.skillService.id}`,
      });
    },
    // 抢单
    receive() {
      let baseUrl = app.getNetAddresss("plugin.be-within-call.frontend.need-order-operate.grab");
      app._postNetWork({
        url: baseUrl,
        data: {
          oid:this.data.order_id
        },
        success: ({data : { data,result,msg }}) => {
          if (result !== 1) {
            app.tips(msg)
            return false;
          }
          app.tips(msg)
          setTimeout(() => {
            wx.navigateTo({
              url:  `/packageJ/anytime_service/my/skill_order/skill_order`,
            });
          },1000)
        }
      });
    }
  }

})